<template>
	<view>
		<!-- 审核 -->
		<u-popup :show="shVisible" @close="close('sh')" round="10" closeable>
			<view class="popup-title" v-if="oper_item.status == 1135">结算单初审</view>
			<view class="popup-title" v-if="oper_item.status == 1138">结算单复审</view>
			<view class="popup-box">
				<u-radio-group v-model="formData.reviewPassed" placement="row" activeColor="#3B75FF">
					<u-radio :name="1" label="通过" :customStyle="{marginRight: '40rpx'}"></u-radio>
					<u-radio :name="2" label="拒绝"></u-radio>
				</u-radio-group>
				<view class="textarea-box">
					<u-textarea v-model="formData.remark" placeholder="请输入审批意见"></u-textarea>
				</view>
				<u-button type="primary" text="提交" color="#3B75FF" :customStyle="{marginTop: '30rpx'}"
					@click="shSubmit"></u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name: "settlementManagement",
		props: {
			value: {
				type: String,
				default: ''
			},
			oper_item: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				shVisible: false,
				formData: {
					reviewPassed: 1,
					remark: '',
				},
			};
		},
		watch: {
			value(val) {
				console.log(val, 'xxxx');
				switch (val) {
					case 'preSettlement_sh':
						this.shVisible = true;
						break;
				}
			}
		},
		methods: {
			close(type) {
				switch (type) {
					case 'sh':
						this.shVisible = false;
						this.formData = {
							reviewPassed: 1,
							remark: '',
						}
						break;
				}
				this.$emit('update:value', '');
			},
			/********** 审核 **********/
			shSubmit() {
				let oper_item = this.oper_item
				let formData = this.formData
				if (formData.reviewPassed == 1) {
					uni.showLoading({
						mask: true
					});
					let audit_type = 1;
					if (oper_item.status == 1135) audit_type = 1;
					if (oper_item.status == 1138) audit_type = 2;
					this.$hApi.settlementStatementPassed({
						quotation_id: "",
						project_id: oper_item.id,
						remark: formData.remark,
						audit_type // this.userInfo.position_id == 7 ? 1 : 2
					}).then(res => {
						console.log(res, 'settlementStatementPassed');
						uni.hideLoading();
						if (res.code == 200) {
							this.$emit('submit', this.value);
							this.close('sh')
						}
						uni.showToast({
							title: res.code == 200 ? "操作成功" : res.message,
							icon: res.code == 200 ? "success" : "error",
						});
					})
				} else {
					if (!formData.remark) {
						this.$refs.uToast.show({
							message: "请输入审批意见",
						})
						return
					}
					uni.showLoading({
						mask: true
					});
					this.$hApi.settlementStatementRejected({
						project_id: oper_item.id,
						remark: formData.remark,
					}).then(res => {
						console.log(res, 'quotationReviewRejected');
						uni.hideLoading();
						if (res.code == 200) {
							this.$emit('submit', this.value);
							this.close('sh')
						}
						uni.showToast({
							title: res.code == 200 ? "操作成功" : res.message,
							icon: res.code == 200 ? "success" : "error",
						});
					})
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	.popup-title {
		height: 46px;
		border-bottom: 2rpx solid #efefef;
		text-align: center;
		line-height: 46px;
		font-size: 30rpx;
	}

	.popup-box {
		padding: 30rpx 20rpx 20rpx;

		.textarea-box {
			margin-top: 30rpx;
		}
	}
</style>